package com.siyao.redvip.ui.activity;

import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.siyao.redvip.R;
import com.siyao.redvip.bean.ResponseTBean;
import com.siyao.redvip.bean.TResponseBean;
import com.siyao.redvip.bean.ZxBean;
import com.siyao.redvip.components.base.BaseFragmentActivity;
import com.siyao.redvip.image.ImageLoaderOptions;
import com.siyao.redvip.network.NetConstans;
import com.siyao.redvip.utils.ToastUtils;
import com.siyao.redvip.utils.Track;
import com.siyao.redvip.volley.NetRequest;
import com.siyao.redvip.volley.VolleyErrorListener;
import com.siyao.redvip.volley.VolleySuccessListener;

/**
 * 健康咨询详情页面
 * 
 * @author lenovo
 * 
 */
public class ZxDetailsActivity extends BaseFragmentActivity {

	private int zxId;
	private TextView textTitle;
	private WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitleText("咨询详情");
		setLeftButton("返回");
	}

	@Override
	protected void beforeInit() {
		Bundle bundle = getIntent().getExtras();
		zxId = Integer.parseInt(bundle.get("zxId").toString());
	}

	@Override
	public void ininlazeLayout() {
		View appView = getLayoutInflater().inflate(
				R.layout.activity_zx_details_fragment, null);
		appMainView.addView(appView, layoutParams);
	}

	@Override
	public void ininlazeView() {
		textTitle = (TextView) findViewById(R.id.text_title);
		webView   = (WebView) findViewById(R.id.web_view);
	}

	@Override
	public void ininlazeData() {
		showPd();
		NetRequest request = new NetRequest(this);
		HashMap<String,String> paramMap = new HashMap<String,String>();
		paramMap.put("id", zxId+"");
		request.doPostRequest(NetConstans.HEALTH_INFO,paramMap, new VolleySuccessListener(){
			@Override
			public void onResponse(String response) {
				super.onResponse(response);
				Track.i(response);
				if (netBean.getStatus() == 1) {
						ResponseTBean<ZxBean> res=gson.fromJson(response, new TypeToken<ResponseTBean<ZxBean>>() {}.getType());
						ZxBean zx=res.getData();
						String content=zx.getContent();
						String title =zx.getTitle();
						textTitle.setText(title);
						webView.loadData(content, "text/html; charset=UTF-8", null);
				}else{
					ToastUtils.makeMesageShort(ZxDetailsActivity.this,getString(R.string.server_error));
				}
				dismissPd();
			}
		}, new VolleyErrorListener(){
			public void onErrorResponse(com.android.volley.VolleyError error) {
				ToastUtils.makeMesageShort(ZxDetailsActivity.this,getString(R.string.server_error));
				dismissPd();
			};
		});
	}

	@Override
	public void onClick(View v) {
		int vid = v.getId();
		switch (vid) {
		case R.id.top_left_btn:
			Intent intent = new Intent(this, ZxActivity.class);
			startActivity(intent);
			finish();
			break;
		default:
			break;
		}
	}
}
